package com.qianli.cashmama.trade.common.utils;

import org.apache.commons.lang.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 字符串过滤
 *
 * @author liuming
 * Created on 下午3:36 2019/3/11.
 */
public class StringFilterUtil {

    /**
     * 去掉换行符
     *
     * @param str
     * @return
     */
    public static String replaceBlank(String str) {
        String dest = "";
        if (str != null) {
            Pattern p = Pattern.compile("\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }

    /**
     * 移除数字
     *
     * @param str
     * @return
     */
    public static String replaceNumber(String str) {
        if (StringUtils.isNotBlank(str)) {
            return str.replaceAll("\\d+", "");
        }
        return str;
    }

    public static void main(String[] args) {
        System.out.println("just\n do it!");
        //System.out.println(StringFilterUtil.replaceBlank("just\n do\r it! \r \t"));

        System.out.println("aa 121lll".replaceAll("\\d+", ""));
    }

}
